package easycloud.ecs.web.util;

import javax.inject.Inject;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Service;

import easycloud.ecs.common.domain.Provider;
import easycloud.ecs.web.service.ProviderService;

@Service
public class ProviderConverter implements Converter<String, Provider> {

	@Inject
	private ProviderService providerService;

	@Override
	public Provider convert(String arg0) {
		Integer providerId = Integer.parseInt(arg0);
		if (providerId >= 0) {
			return providerService.getProvider(providerId);
		} else {
			return null;
		}
	}
}